//
//  PPSign.m
//  PPNetworking
//
//  Created by ppwang on 2021/12/13.
//

#import "PPSign.h"
#import "PPNetCategorys.h"

@implementation PPSign

+ (NSString *)createParamters:(NSDictionary *)dict {
    NSMutableString *string = [[NSMutableString alloc] init];
    NSArray *allKeys = [dict pp_allKeysSorted];
    for (NSString *key in allKeys) {
        NSString *value = [dict objectForKey:key];
        value = [NSString stringWithFormat:@"%@", value];
        if ([value isKindOfClass:[NSString class]] &&
            value.length > 0 &&
            ![key isEqualToString:@"key"] &&
            ![key isEqualToString:@"sign"]) {
            
            [string appendString:key];
            [string appendString:@"="];
            [string appendString:value];
            [string appendString:@"&"];
            
        }
    }
    if (string.length > 0) {
        return [string substringToIndex:([string length]-1)];
    }
    return string;
}

+ (NSString *)createSign:(NSDictionary *)dict {
    NSMutableString *string = [[NSMutableString alloc] init];
    [string appendString:[PPSign createParamters:dict]];
    [string appendString:[NSString stringWithFormat:@"&key=%@", @"51d8bd7959cafcf4bd92a8db8dd15b34"]];
    return [string pp_md5String];
}

@end


